// pages/shanghjhexiao/shanghjhexiao.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wordKey: '',
    jihuo: '',
    mealsList: '',
    xinxi: true,
    length: '', //数据长度
    flag: true, //设置节流
    PRIZE_EXPLAIN:'',
  },



  search_but() {
    this.setData({
      mealsList: app.globalData.mealsList
    });
    var that = this
    if (that.data.wordKey == "") {
      wx.showToast({
        title: '请输入手机号',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.request({
        url: app.globalData.interface+'/ankangdabiao/API_6711_wangdiananKangxinyongkaCouponList',
        method: 'GET',
        data: {

          USER_COUPON_PHONE: that.data.wordKey,
          OPEN_ID: this.data.openid, //用户OPEN_ID
          session_key:this.data.session_key,
          OPEN_UUID:this.data.jiami,
          EMPLOYEE_ID: that.data.mealsList,
    
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          console.log(res.data.wangdianuserCoupon);
          that.setData({
            // PRIZE_EXPLAIN: res.data.data.MONEY,
            jihuo: res.data.wangdianuserCoupon,
            xinxi: false,
          })
        }
      })
    }
  },




  buttonji() {
    var that = this
    wx.request({
      url: app.globalData.interface+'/ankangdabiao/API_6713_anKangxinyongkaAddCoupon',
      method: 'POSt',
      data: {

        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key:this.data.session_key,
        OPEN_UUID:this.data.jiami,
    
        USER_ASSETS_ID:that.data.jihuo.USER_ASSETS_ID,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data);
        if (res.data.result == "error") {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
          that.setData({
            xinxi:true,
            wordKey:'',

          })

        }
      }
    })
  },












  buttonjiwushi() {
    var that = this
    wx.request({
      url: app.globalData.interface+'/ankangdabiao/API_6715_anKangxinyongkaAddCouponshoushua',
      method: 'POSt',
      data: {
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key:this.data.session_key,
        OPEN_UUID:this.data.jiami,
        USER_ASSETS_ID:that.data.jihuo.USER_ASSETS_ID,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data);
        if (res.data.result == "error") {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
          that.setData({
            xinxi:true,
            wordKey:'',

          })

        }
      }
    })
  },

















  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    console.log(value);



    this.setData({
      mobile: value,
    })

    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        wordKey: '',
        mobileFormat: false,
        xinxi: true,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        wordKey: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        wordKey: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})